import { Director, director, instantiate, Prefab, resources, Tween } from "cc"
import { AudioManager } from "./framework/AudioManager"

export class PlayableSetupConfig{
  protected onInitialize(): void {
    AudioManager.instance.playMusic("bm_bgm");
    // 当有场景重新加载，表示当前游戏已经结束，做一些清理工作
    director.on(Director.EVENT_BEFORE_SCENE_LOADING, this.onShutdown, this)
    // const ending = instantiate(resources.get("prefabs/endingView", Prefab))
    // director.getScene().getChildByName("Canvas").addChild(ending)
  }

  // 提前加载资源
  public getSyncPreloadAssets() {
    
  }

  protected static initGameView(): void {
    const gameViewPrefab = resources.get("prefabs/gameView", Prefab)
    const canvasNode = director.getScene().getChildByName("Canvas")
    const gameView = instantiate(gameViewPrefab)
    gameView.setParent(canvasNode)
  }

  public onShutdown(): void {
    Tween.stopAll()
  }
}